package com.eastfair.es.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.eastfair.annotation.log.entity.OptLogDTO;
import com.eastfair.core.base.R;
import com.eastfair.elasticsearch.model.PageResult;
import com.eastfair.es.entity.PointLog;
import com.eastfair.es.service.PointLogService;
import com.eastfair.es.service.StudentService;
import com.eastfair.es.vo.PointLogVo;
import com.eastfair.es.vo.SysLogVO;
import com.eastfair.log.point.PointEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * elasticsearch 搜索引擎
 *
 * @author zhoudong
 * @version 0.1
 * @date 2018/12/13 15:33
 */
@Slf4j
@Service
public class PointLogServiceImpl implements PointLogService {


    @Override
    public R test() {
        return null;
    }

    @Override
    public List<PointLogVo> assembleLogList(List<PointLog> pointLogList) {
        if (pointLogList == null || pointLogList.isEmpty()) {
            return null;
        }
        List<PointLogVo> pointLogVoList = new ArrayList<>();
        for (PointLog pointLog : pointLogList) {
            pointLogVoList.add(assembleLog(pointLog));
        }
        return pointLogVoList;
    }

    @Override
    public PointLogVo assembleLog(PointLog pointLog) {
        if (pointLog == null) {
            return null;
        }
        PointLogVo pointLogVo = new PointLogVo();
        BeanUtils.copyProperties(pointLog, pointLogVo);
        if (PointEnum.SYSLOG.getCode().equals(pointLog.getPointName())) {
            SysLogVO sysLogVO = JSONObject.parseObject(pointLog.getMsg(), SysLogVO.class);
            pointLogVo.setSysLogVO(sysLogVO);
            pointLogVo.setMsg(null);
        }
        return pointLogVo;
    }
}
